package com.itfenghuang.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itfenghuang.domain.User;
import com.itfenghuang.mapper.UserMapper;
import com.itfenghuang.service.UserService;
import com.itfenghuang.vo.PageVo;
import com.itfenghuang.vo.SelectVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImp implements UserService {

    //引入mapper
    @Resource
    UserMapper userMapper;

    //1.注册
    @Override
    public void register(User user) {
        userMapper.addUser(user);
    }
    //2.根据账号查询用户
    @Override
    public User selectOne(String username) {
        return userMapper.selectOne(username);
    }
    //3.分页查询所有信息
    @Override
    public PageInfo<User> selectAll(PageVo pageVo) {
        //当前页和每页显示的条数
        PageHelper.startPage(pageVo.getPageNum(),pageVo.getPageSize());
        List<User> userList=userMapper.selectAll();
        //使用PageInfo 封装数据
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }
    //4.条件查询用户
    @Override
    public PageInfo<User> selectByUser(SelectVo selectVo) {
        //当前页和条数
        PageHelper.startPage(selectVo.getPageNum(),selectVo.getPageSize());
        List<User> users=userMapper.selectByUser(selectVo);
        //使用PageInfo 封装数据
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }
    //5.删除用户信息
    @Override
    public void deleteByIds(List<Integer> ids) {
        userMapper.deleteByIds(ids);
    }
    //6.根据id查询用户
    @Override
    public List<User> exportUserinfo(List<Integer> ids) {
        return userMapper.exportUserinfo(ids);
    }
    //7.查询用户
    @Override
    public List<User> exportAllUserinfo() {
        return userMapper.selectAll();
    }

    //10.修改用户信息
    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }
}
